/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package supportlearning.session;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import supportlearning.entities.Account;
import supportlearning.entities.CMSClass;
import supportlearning.entities.StudentProfile;

/**
 *
 * @author Huy
 */
@Stateless
public class createstudentprofile implements createstudentprofileLocal {
    @PersistenceContext(unitName = "eprojectSupportLearning-ejbPU")
    private EntityManager em;

    public int CreateStudentProfile(int id, String Desc, int Classid) {
        Account acc = em.find(Account.class, id);
       CMSClass clss = em.find(CMSClass.class, Classid);
        if (acc == null) {
            return 1;//AccountID is valid.
        } else if (clss == null) {
            return 2;//ClassID is valid.
        } else {
            StudentProfile student = new StudentProfile();
            student.setAccount(acc);
            student.setDescription(Desc);
            student.setCMSClass(clss);
            em.persist(student);
            return 3;//ok
        }
    }

    public void persist(Object object) {
        em.persist(object);
    }
}
